package io.zhile.crack.atlassian.plugins.zephyr;


import java.security.PublicKey;


public class LicenseVerifier {

    public static void main(String[] args) throws Exception {
//         版本号#版权类型，从0~8，#描述#licenseId#
        String licenseKey = "6.0.1.60108991#" + // 版本号，查看安装插件的版本
                "1#" +  /*
                            版权类型:
                                0: io.zhile.crack.atlassian.license.LicenseType.ACADEMIC
                                1: io.zhile.crack.atlassian.license.LicenseType.COMMERCIAL
                                2: io.zhile.crack.atlassian.license.LicenseType.COMMUNITY
                                3: io.zhile.crack.atlassian.license.LicenseType.DEMONSTRATION
                                4: io.zhile.crack.atlassian.license.LicenseType.DEVELOPER
                                9: io.zhile.crack.atlassian.license.LicenseType.HOSTED
                                5: io.zhile.crack.atlassian.license.LicenseType.NON_PROFIT
                                6: io.zhile.crack.atlassian.license.LicenseType.OPEN_SOURCE
                                7: io.zhile.crack.atlassian.license.LicenseType.PERSONAL
                                8: io.zhile.crack.atlassian.license.LicenseType.STARTER
                        */
                "Unlimited license by http://www.kevin.com#" +  //描述信息 description
                "LIDSEN-L" + System.currentTimeMillis() + "#" + // licenseId
                "04-04-2021#" +  // tempPurchaseDateString，格式为 MM-dd-yyyy
                "12-31-2099#" + // tempMaintenanceExpiry，格式为 MM-dd-yyyy
                "12-31-2099#" + // tempLicenseExpiryDateString，格式为 MM-dd-yyyy
                "1#" +  // evaluationType: 写1即可
                "1#" +  // unlimitedUsersFlag，是否限制使用用户的个数，如果为1，可以最多使用9999个用户
                "9999#" +// 当 unlimitedUsersFlag 为1时，任意值，当 unlimitedUsersFlag为 0 时指定限制使用用户的个数，0~9999
                "www.kevin.com#" + // organisation
                "kevin#" +  //  organisationId
                "huankai@139.com#";  // organisation Email
        final String licenseKeyEncoded = Base64Coder.encode(licenseKey);
        System.out.println(licenseKeyEncoded);
        final String licenseKeyDecoded = Base64Coder.decode(licenseKeyEncoded);
        System.out.println(licenseKeyDecoded);

        final EncryptionUtil encryptionUtil = new EncryptionUtil();
        encryptionUtil.generateKeys();
        String signature = encryptionUtil.sign(licenseKeyDecoded);
        final PublicKey publicKey = encryptionUtil.getPublic();
        String encodedPublicKey = new String(Base64Coder.encode(publicKey.getEncoded()));
        String result = licenseKeyEncoded + "#" + signature + "@" + encodedPublicKey;

        encryptionUtil.verify(licenseKeyDecoded, signature, publicKey);
        System.out.println("------>result:\r\n" + result);
    }
}